#include "mat_score.h"
#include "mat_sounds.h"

#include "font/font_manager.h"

MATScore::MATScore() :		m_PreviousScore(0),
							m_pWidgetBox(NULL)
{
	
}
	

void		MATScore::Load(const std::string& File, ui::UIWidget* pWidgetBox)
{
	m_LEDNumber.Load(File);
	m_pWidgetBox = pWidgetBox;
}
	
void		MATScore::Tick(float dt)
{
	if(m_ScoreShow < m_ScoreTarget)
	{
		m_ScoreShow += (float)(m_Diff * dt);
		if( (float)(m_ScoreShow - (float)m_PreviousScore) > 1.0f)
			MATSounds::Instance().PlaySoundSFX(MATSounds::UI_SCORE_TICK);
		m_PreviousScore = (int)m_ScoreShow;
		
	}

	if(m_ScoreShow >= m_ScoreTarget)
		m_ScoreShow = (float)m_ScoreTarget;
}

void		MATScore::Add(int Score)
{
	m_ScoreTarget += Score; 
	m_Diff = m_ScoreTarget - m_ScoreShow;
	
}

void		MATScore::Render(float Scale)
{
	m_LEDNumber.Draw((int)m_ScoreShow, m_pWidgetBox , 1 , true);
	
}

void		MATScore::InitValue(int Score)
{
	m_ScoreShow = (float)Score;
	m_ScoreTarget = Score;
	m_Diff = 0;
}
